using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Viettel.VOFFICE.DAO.Models.Mapping
{
    public class NodeMap : EntityTypeConfiguration<Node>
    {
        public NodeMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.Description)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("Nodes");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.FlowId).HasColumnName("FlowId");
            this.Property(t => t.RoleId).HasColumnName("RoleId");
            this.Property(t => t.IsDocNode).HasColumnName("IsDocNode");
            this.Property(t => t.IsStart).HasColumnName("IsStart");
            this.Property(t => t.CreatedAt).HasColumnName("CreatedAt");
            this.Property(t => t.UpdatedAt).HasColumnName("UpdatedAt");
            this.Property(t => t.CreatorId).HasColumnName("CreatorId");

            // Relationships
            this.HasOptional(t => t.aspnet_Roles)
                .WithMany(t => t.Nodes)
                .HasForeignKey(d => d.RoleId);
            this.HasRequired(t => t.Flow)
                .WithMany(t => t.Nodes)
                .HasForeignKey(d => d.FlowId);

        }
    }
}
